package com.zwz.controller;

import com.zwz.dto.BankruptcyDTO;
import com.zwz.service.BankruptcyReorganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/bankruptcies")
public class BankruptcyReorganizationController {

    @Autowired
    private BankruptcyReorganizationService bankruptcyService;

    @PostMapping
    public ResponseEntity<?> create(String enterpriseId) {
        try {
            BankruptcyDTO dto = bankruptcyService.createWithMain(enterpriseId);
            return ResponseEntity.status(HttpStatus.CREATED).body(dto);
        } catch (IllegalArgumentException e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        } catch (DataIntegrityViolationException e) {
            return ResponseEntity.badRequest().body("数据关联错误");
        }
    }

//    @GetMapping("/active")
//    public ResponseEntity<List<BankruptcyReorganization>> getActive() {
//        return ResponseEntity.ok(bankruptcyService.getActiveBankruptcies());
//    }
//
//    @GetMapping("/court/{courtName}")
//    public ResponseEntity<List<BankruptcyReorganization>> getByCourt(
//            @PathVariable String courtName) {
//        return ResponseEntity.ok(bankruptcyService.getByCourt(courtName));
//    }
}